<template>
  <!--饮品-->
  <div class="yinpin">
    <p><img src="../../../assets/banner.png" alt="" width="100%"></p>

    <wv-group title="验证类型" class="cishu">
      <wv-cell
        title="验证类型"
        is-link
        :value="shopFree.freeName"
        @click.native="shopFreePickerShow = true"
      />
      <wv-picker
        :visible.sync="shopFreePickerShow"
        :columns="shopFreeListColumns"
        value-key="freeName"
        @confirm="confirmShopFree"
      />
    </wv-group>
    <wv-group title="数量" class="cishu">
      <wv-input placeholder="数量"  v-model="checkRecord.useNum" :readonly="true"></wv-input>
    </wv-group>
    <wv-group title="备注" class="beizhus">
      <wv-textarea placeholder="请输入备注" :rows="6" show-counter max-length="500" v-model="checkRecord.remark"></wv-textarea>
    </wv-group>
    <p class="offer" @click="goUseCheck()">使用验证</p>

    <div class="model" v-show="isVisible">
      <div class="bg"></div>
      <div class="modelContent">
        <img src="../../../assets/close.png" alt="" width="15" @click="isVisible=false">
        请确认选择的会员尊享服务类 型是否正确，使用验证后将无法更改。
        <p class="btn">
          <button @click="goEmployeeCheckFree(checkRecord)">确定</button>
          <button @click="isVisible=false">取消</button>
        </p>
      </div>
    </div>

  </div>
</template>

<script type="text/ecmascript-6">
  import {Picker, Toast} from 'we-vue'
  import {getEmployeeCancheckFree, employeeCheckFree} from '../../../../test/unit/http'
  export default {
    name: '',
    props: {},
    data() {
      return {
        payType: '南宁贵宾厅休息服务',
        shopFreePickerShow: false,
        shopFree: [{freeName: ''}],
        shopFreeListColumns: [
          {
            values: [],
            defaultIndex: 0
          }
        ],
        checkRecord: {},
        isVisible: false
      };
    },
    methods: {
      confirmShopFree(picker) {
        this.shopFree = picker.getValues()[0];
        this.checkRecord['serverName'] = this.shopFree.freeName;
        this.checkRecord['serverId'] = this.shopFree.shopFreeId;
      },
      getEmployeeCancheckFreeData() {
        getEmployeeCancheckFree({}).then(res => {
          console.log(res);
          if (res.code == 100) {
            var shopFreeList = res.object;
            this.shopFreeListColumns[0].values = shopFreeList;
            this.shopFree = shopFreeList[0];
            this.checkRecord['serverName'] = this.shopFree.freeName;
            this.checkRecord['serverId'] = this.shopFree.shopFreeId;
            this.checkRecord['checkType'] = 3;
          }
        })
      },
      checkForm(checkRecord) {
        var msg = {};
        if (this.$myUtils.isNull(checkRecord.serverName)) {
          msg['result'] = false;
          msg['info'] = '请选择免费饮品';
          return msg;
        }
        msg['result'] = true;
        msg['info'] = '校验成功';
        return msg;
      },
      goUseCheck() {
        this.isVisible = true;
      },
      goEmployeeCheckFree(checkRecord) {
        var result = this.checkForm(checkRecord);
        if (!result) {
          Toast.text(result.info);
          return;
        }
        employeeCheckFree(checkRecord).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.$router.push({path: 'success'})
          }else{
            Toast.text(res.info);
          }
        })
      }
    },
    created() {
      var accountGoodsId = this.$route.query.accountGoodsId;
      this.checkRecord['accountGoodsId'] = accountGoodsId;
      this.checkRecord['useNum'] = "1";
      this.getEmployeeCancheckFreeData();
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelContent {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 40px 10px 20px;
    width: 80%;
    text-align: left;
    img {
      position: absolute;
      right: 10px;
      top: 10px
    }
    .btn {
      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: calc(50% - 20px);
        border-radius: 8px;
        margin-top: 25px;
      }
      :last-child {
        background-color: #ccc;

      }
      :first-child {
        background-color: #f98e3c;
        margin-right: 20px;

      }
    }

  }

  .offer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: #f98e3c;
    height: 50px;
    line-height: 50px;
    color: #fff;
  }

  .on {
    background-image: url(../../../assets/cheaked.png);
    background-size: 100% 100%;
  }
</style>
